package club.justwill.single.persistence.jpo;

import club.justwill.single.persistence.support.UserAliasesBase;
import club.justwill.single.persistence.support.UserAliasesPK;

import javax.lang.model.element.Name;
import javax.persistence.*;
import java.io.Serializable;

/**
 * Created by luoyu on 15-12-24.
 */
@Entity
@Table(name = "user_aliases")
@IdClass(UserAliasesPK.class)
@NamedQueries({
        @NamedQuery(name="UserAliases.getByTypeAndNumber",
                query="select ua from UserAliases ua where ua.type=:type and ua.aliasName=:alipayNumber"),
        @NamedQuery(name="UserAliases.getByUserIdAndType",
                query = "select ua from UserAliases ua where ua.userId = :userId and ua.type = :type")

})
public class UserAliases extends UserAliasesBase {

    //一个用户可以有多个别名 别名跟用户是多对一关系 多方
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "user_id", referencedColumnName = "user_id", insertable = false, updatable = false)
    private User user;

    @Id
    @Column(name = "user_id")
    private Long userId;

    @Id
    @Column(name = "type")
    private Integer type;

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public Long getUserId() {
        return userId;
    }

    public void setUserId(Long userId) {
        if(userId == null) {
            this.userId = 0L;
        } else {
            this.userId = userId;
        }
    }

    public Integer getType() {
        return type;
    }

    public void setType(Integer type) {
        this.type = type;
    }

}
